package com.platform.common.mybatis.dialect;

import com.platform.common.logger.annotation.EnableLogger;
import com.platform.common.util.SqlUtil;
import org.apache.log4j.Logger;

public class SQLServerDialect implements Dialect {

    @EnableLogger
    private static Logger logger;


    /**
     * 将SQL语句包装成分页查询SQL
     *
     * @param querySql SQL语句
     * @param offset   开始行
     * @param limit    查询条数
     * @return SQL语句
     */
    @Override
    public String getLimitString(String querySql, int offset, int limit) {
        if (offset > 0) {
            throw new UnsupportedOperationException("query result offset is not supported");
        }

        String sql = new StringBuffer(querySql.length() + 8)
                .append(querySql)
                .insert(SqlUtil.getAfterSelectPoint(querySql), " top " + limit)
                .toString();

        logger.info("SQLServerDialect getLimitString to sql :" + sql);

        return sql;
    }
}
